#include<iostream>
#include<cstdio>
#include<list>
using namespace std;

int m,n,ta=0;
list<int> monkey;

int ans(int n,int m){
	monkey.clear();
	for(int i=1;i<=n;i++)
		monkey.push_back(i);
	list<int>::iterator it=monkey.begin();
	while(monkey.size()>1){
		for(int i=1;i<m;i++){
			++it;
			if(it==monkey.end()) it=monkey.begin();
		}
		it=monkey.erase(it);
		if(it==monkey.end()) it=monkey.begin();
	}
	return monkey.front();
}

int main(){
	while(cin>>n){
		if(n == 0){
			cin>>m;
			if(m == 0)	break;
		}
		cin>>m;
		cout<<ans(n,m)<<endl;
	}
	return 0;
}
